{% extends "base.html" %}
{% import "_macros.html" as macros %}

{% block title %}{{visted_user.username}}的个人信息{% endblock %}

{% block page_content %}
<div class="page-header">
    <img class="img-rounded profile-thumbnail" src = "{{ visted_user.get_image_url(size = 256) }}">
    <div class="profile-header">
        <h1>{{visted_user.username}}</h1><br/>
        {% if visted_user.location %}
            地址：{{visted_user.location}}<br/>
        {% endif %}
        {% if current_user.is_administer() or visted_user == current_user %}
            <a href="mailto:{{visted_user.email}}">邮箱：{{visted_user.email}}</a><br/>
        {% endif %}
        {% if visted_user.about_me %}<p>关于自己：{{visted_user.about_me}}</p>{% endif %}
        <p>
            帐号创建于{{visted_user.register_time}} | 最后访问于{{visted_user.last_time}}<br/>
            该用户一共发表了<span style="color: red">{{ visted_user.posts.count() }}</span>篇博文,
            <span style="color: red">{{ visted_user.comments.count() }}</span>篇评论。
        </p>

        <p>
            {% if current_user.can(Permission.FOLLOW) and current_user != visted_user %}
                {% if not current_user.is_following(visted_user) %}
                    <a href="{{ url_for('main.follow', username = visted_user.username) }}"
                       class="btn btn-primary">关注</a>&nbsp;&nbsp;&nbsp;&nbsp;
                {% else %}
                    <a href="{{ url_for('main.unfollow', username = visted_user.username) }}"
                       class="btn btn-primary">取消关注</a>&nbsp;&nbsp;&nbsp;&nbsp;
                {% endif %}
            {% endif %}
            <a href="{{ url_for('main.followers',username = visted_user.username) }}">
                该用户的关注：<span class="badge">{{ visted_user.followers.count() - 1 }}</span>
            </a>
            <a href="{{ url_for('main.followeds',username = visted_user.username) }}">
                该用户被谁关注：<span class="badge">{{ visted_user.followeds.count() - 1 }}</span>
            </a>
            {% if current_user.is_authenticated and visted_user != current_user and visted_user.is_following(current_user) %}
                |<span class="label label-danger">关注了你</span>
            {% endif %}
        </p>

        {% if current_user.is_administer() %}
            <a class="btn btn-danger" href="{{url_for('main.editinfo_admin', id = visted_user.id)}}">修改资料(All)</a>
        {% elif visted_user == current_user %}
            <a class="btn btn-default" href="{{url_for('main.editinfo')}}">修改资料</a>
        {% endif %}
    </div>
</div>
    <h3>用户足迹</h3>
    <div class = "post-tabs">
        <div class="nav nav-tabs">
            <li {% if showwhat == "post" %} class="active" {% endif %}>
                <a href="{{ url_for('main.userinfo', username = visted_user.username, showwhat = "post") }}">
                    博客
                </a>
            </li>
            <li {% if showwhat == "comment" %} class ="active" {% endif %}>
                <a href="{{ url_for('main.userinfo', username = visted_user.username , showwhat = "comment") }}">
                    评论
                </a>
            </li>
        </div>
        {% if showwhat == "post" %}
            {% include "_post.html" %}
        {% else %}
            {% include "_comments.html" %}
        {% endif %}
    </div>
    {% if pagination %}
        <div class="pagination">
            {{ macros.pagination_widget(pagination, "main.userinfo", username = visted_user.username, showwhat = showwhat) }}
        </div>
    {% endif %}
{% endblock %}